package org.xbzheng.restful_study.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xbzheng.restful_study.dao.ResourceDao;
import org.xbzheng.restful_study.model.Resources;

import java.util.List;

@Service
public class ResourceService {

    @Autowired
    private ResourceDao resourcesDao;

    public List<Resources> findAll(){
        return resourcesDao.findAll();
    }

    public void save(Resources resources){
        resourcesDao.save(resources);
    }

    public void remove(List<Resources> resources){
        for(Resources resource : resources){
            resourcesDao.delete(resource);
        }
    }

    public List<Resources> findTopRes(){
        return findTopRes();
    }

    public List<Resources> findLeftMenu(String username, String resourceType){
        return resourcesDao.findLeftMenu(username, resourceType);
    }

    /**
     * 获取指定页面的权限控制
     * @param username
     * @param owner 哪一个页面
     * @return
     */
    public List<Resources> findPageResources(String username, String owner){
        return resourcesDao.findPageResources(username, owner);
    }
}
